package com.leyu.mall.site.home.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.leyu.mall.common.facade.ICmsChannelFacade;
import com.leyu.mall.service.goods.IGoodsBaseService;
/**
 * 〈一句话功能简述〉 〈功能详细描述〉
 * @author OOKK
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */

@Controller
@Scope(value = "prototype")
@RequestMapping("")
public class SiteGoodsController
{
	@Autowired
	private ICmsChannelFacade	cmsChannelFacade;
	@Resource(name = "goodsBaseServiceImpl")
	private IGoodsBaseService	goodsBaseServiceImpl;

	@ExceptionHandler(Exception.class)
	public String exception(Exception e, HttpServletRequest request)
	{
		request.setAttribute("exception", e);
		return "/error.html";
	}

	@RequestMapping(value = "item/{itemIDS}", method = RequestMethod.GET)
	public String delete(Model model, @PathVariable String itemIDS)
	{
		try
		{
			model.addAttribute("list", cmsChannelFacade.getDisplayChannelList());
			System.out.println("-------111111-goodsID-----------------------" + itemIDS);
			Long goodsID = Long.parseLong(itemIDS.split("_")[2]);
			model.addAttribute("itemdetail", goodsBaseServiceImpl.getGoodsBaseById(goodsID));
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "goods/item.html";
	}
}
